<?php
    session_start();
    include_once ('inc/class/Util.class.php');
    //Sistema per sapere il nome della pagina corrente e aggiornare i tab del menu
    $_SESSION['current_page'] = Util::getPage();  
    include_once ('inc/class/User.class.php');
    include_once ('inc/class/Form.class.php');
    include_once ('inc/global/global.inc.php');
    include_once ('inc/code/head.php');
    if(isset($utente)){
        
        
    //Invio dei dati del ticket quando di preme invia
    if(isset($_REQUEST['send_ticket']))
    {
        $oggi = date('d.m.y', time());
        $tick = User::inserisci_ticket($utente->nomeCognome(), $utente->mail, $_POST[messaggio], $utente->id, $oggi, $_POST[val_id_topic]);

        if($tick)
            echo "<script> alert('Ticket inviato') </script>";
    }
    
?>
<div id="Content">

    <div id="One">
          <H2>&raquo; Ticket</H2>

          <p>Crea un nuovo ticket</p>
                <blockquote>
                <fieldset>
                <legend>Invia ticket</legend>

                <form action="home.php" method="post">

                <table border="0">
                    <tbody>
                        <tr> <!-- Form per inviare i ticket, ricuperiamo i dati utente e la data -->
                            <td><label for="nome">Cognome Nome</label></td>
                            <td><input type="text" name="nome" id="nome" disabled="true" value="<?php echo $utente->cognome . ' ' . $utente->nome; ?>" /></td>
                        </tr>
                        <tr>
                            <td><label for="email">Email</label></td>
                            <td><input type="text" name="email" id="email" disabled="true" value="<?php echo $utente->mail; ?>" /></td>
                        </tr>
                        <tr>
                            <td><label for="email">Topic</label></td>
                            <td><select name="val_id_topic" id='id_topic'>
                                <?php
                                //Ricuperare i diversi topic presenti e stamparli nella select
                                $topic = "select id_topic, nome_topic from topic";
                                $result_topic = mysql_query($topic);
                                $options = "";
                                while($row_utente = mysql_fetch_array($result_topic)) {
                                    $options .= "<option value='".$row_utente["id_topic"]."'>" . $row_utente['nome_topic'] . "</option>";
                                }
                                echo $options;
                                ?>

                                </select></td>
                        </tr>
                        <tr>
                            <td><label for="messaggio">Messaggio</label></td>
                            <td><textarea name="messaggio" id="messaggio" cols="30" rows="10"></textarea></td>
                        </tr>
                        <tr>
                            <td><input name="data" type="hidden" value="<?php $oggi ?>'"></input></td>
                        </tr>

                        <tr>
                            <td><input type="submit" id="submit" name="send_ticket" value="Invia" /></td>
                        </tr>
                    </tbody>
                </table>
                </form>

                </fieldset>
                </blockquote>

    </form>
</div>

</div>
</div>
    
<?php
    include ('inc/code/footer.php');
    }
    
    
    else{
        Util::logoutRedirect();
    }
?>